package objects
{
	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	
	/**
	 * ...
	 * @author Ja
	 */
	public class MyButton extends SimpleButton
	{
		private var _txt:String = "";
		private var color:uint;
		public function MyButton(txt:String = "",width:Number = 40, height:Number = 20,color:uint=0x000000)
		{
			this.color = color;
			_txt = txt;
			
			upState = new States(_txt,width, height, color);
			downState = new States(_txt,width, height, 0xcccccc);
			overState = new States(_txt,width, height,  0x444444);
			hitTestState = new States(_txt,width, height, 0x000000);
		
		}
		
		public function get txt():String 
		{
			return _txt;
		}
		
		public function set txt(value:String):void 
		{
			_txt = value;
			
			upState = new States(_txt,width, height,  color);
			downState = new States(_txt,width, height, 0xcccccc);
			overState = new States(_txt,width, height, 0x444444);
		}
	
	}

}
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;

class States extends Sprite
{
	private var fld:TextField;
	private var format:TextFormat;
	
	public function States(txt:String = "", width:Number = 40, height:Number = 20, color:uint = 0x000000)
	{
		graphics.beginFill(color)
		graphics.drawRoundRect(0, 0, width, height, height / 2, height / 2);
		graphics.endFill();
		
		if (txt != "")
		{
			fld = new TextField();
			fld.text = txt;
			fld.width = width;
			fld.height = height;
			fld.autoSize = TextFieldAutoSize.CENTER;
			format = new TextFormat("Arial", 12, 0xffffff);
			format.align = TextFormatAlign.CENTER;
			//fld.defaultTextFormat = format;
			fld.setTextFormat(format)
			addChild(fld);
			/*if (fld.textWidth + 4 > width)
			{
				width = fld.textWidth + 4;
				graphics.clear();
				graphics.beginFill(color)
				graphics.drawRoundRect(0, 0, width, height, height / 2, height / 2);
				graphics.endFill();
				fld.width = width;
				fld.height = height;
				addChild(fld);
			}*/
		}
	
	}
}